var t = require("../../../../@babel/runtime/helpers/toConsumableArray"), a = getApp();

Page({
    data: {
        language: "",
        info: {},
        active: "",
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        timer: null,
        nowTime: new Date().getTime() / 1e3
    },
    onLoad: function(t) {
        this.getData(0);
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        clearTimeout(this.data.timer);
    },
    onPullDownRefresh: function() {
        this.getData(0);
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : wx.showToast({
            title: "没有更多数据",
            icon: "none"
        });
    },
    onShareAppMessage: function() {},
    getData: function(t) {
        var e = this, o = {};
        console.log(t), o.art = "buyList", 0 == t ? o.state = 1 : 1 == t ? o.state = 2 : 2 == t && (o.state = 3);
        var i = a.getNetAddresss("plugin.together-purchase.api.index.getTogetherData");
        a._getNetWork({
            url: i,
            data: o,
            success: function(t) {
                var a = t.data;
                1 == a.result ? (e.setData({
                    total_page: a.data.buyList.last_page,
                    isLoadMore: !0,
                    info: a.data.buyList.data,
                    page: a.data.buyList.current_page
                }), e.data.total_page || e.setData({
                    total_page: 0
                })) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            }
        });
    },
    gotoOrder: function(t) {
        var a = t.target.dataset.id || t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/member/orderdetail/orderdetail?order_id=" + a + "&orderType=groupsBuy"
        });
    },
    operation: function(t) {
        var a = t.target.dataset.item || t.currentTarget.dataset.item, e = t.target.dataset.order_id || t.currentTarget.dataset.order_id;
        "together_purchase_pay" == a.value ? this.toPay(e, a) : this.publicMessage(a, e);
    },
    publicMessage: function(t, e) {
        console.log(t);
        var o = this;
        t.api && wx.showModal({
            title: "提示",
            content: "确定".concat(t.name, "?"),
            success: function(i) {
                if (i.confirm) {
                    var s = "";
                    s += a.getNetAddresss(t.api), s += "&order_id=" + e, a._getNetWork({
                        url: s,
                        success: function(a) {
                            var e = a.data;
                            1 == e.result ? (o.getdata(), wx.showToast({
                                title: "".concat(t.name, "成功"),
                                icon: "success",
                                duration: 1500,
                                success: function() {}
                            })) : wx.showToast({
                                icon: "none",
                                title: e.msg,
                                duration: 1e3
                            });
                        },
                        fail: function(t) {
                            console.log(t);
                        }
                    });
                }
            }
        });
    },
    toPay: function(t, a) {
        wx.navigateTo({
            url: "/packageD/buy/orderPay/orderPay?order_id=" + t + "&status=2&api=" + a.api
        });
    },
    gotoHome: function() {
        wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    clickAdd: function(t) {
        var a = t.target.dataset.id || t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageB/member/group_buy/group_buy_detail/group_buy_detail?&id=" + a
        });
    },
    getMoreData: function() {
        var e = this;
        this.setData({
            isLoadMore: !1
        });
        var o = {};
        if (0 == this.data.active ? o.state = 1 : 1 == this.data.active ? o.state = 2 : 2 == this.data.active && (o.state = 3), 
        o.art = "buyList", !(this.data.page >= this.data.total_page)) {
            var i = this.data.page;
            i += 1, this.setData({
                page: i
            }), o.page = i;
            var s = a.getNetAddresss("plugin.together-purchase.api.index.getTogetherData");
            a._getNetWork({
                url: s,
                data: o,
                success: function(a) {
                    e.setData({
                        isLoadMore: !0
                    });
                    var o = a.data;
                    if (1 == o.result) {
                        var i = o.data.buyList.data, s = [].concat(t(e.data.info), t(i));
                        e.setData({
                            info: s,
                            page: o.data.buyList.current_page
                        });
                    } else {
                        var r = e.data.page;
                        r -= 1, e.setData({
                            page: r,
                            isLoadMore: !1
                        }), wx.showToast({
                            icon: "none",
                            title: o.msg,
                            duration: 1500
                        });
                    }
                }
            });
        }
    },
    changeData: function(t) {
        this.setData({
            active: t.detail.index
        }), this.getData(t.detail.index);
    }
});